﻿import com.dinmax.isolution.*

class ThemeEditorGUI
extends MovieClip {
	
	private var theme:Theme;
	private var listener:WindowThemesGUI;
	
	function ThemeEditorGUI(){
		if(this._parent._parent instanceof WindowThemesGUI)	this.listener = WindowThemesGUI(this._parent._parent);
		this["mcBtnName"]._visible = false;
		return;
	}
		
	public function getTheme():Theme{
		
		return this.theme;
	}
	public function setTheme(newTheme:Theme):Void{
		this.theme = newTheme;
		this.refresh();
		return;
	}
		
	public function refresh():Void {
		
		//antes de empezar saco el foco de todo
		Selection.setFocus(null);
				
		this["txt_name"].text = this.theme.getName();
				
		var r = this;
		
		this["mcBtnName"]._visible = false;
		this["mcBtnName"].onPress = function(){
			//com.dinmax.isolution.HCC.setThemeName(r.theme.getId(), r["txt_name"].text);
			return;
		}
				
		this["txt_name"].onKeyUp = function(){
			if(Key.getCode() == Key.ENTER){
				if(this.text != r.theme.getName()){
					//com.dinmax.isolution.HCC.setThemeName(r.theme.getId(), this.text);
					this.onKillFocus();
				}
								
			} else if(Key.getCode() == Key.ESCAPE) {
				this.text = r.theme.getName();
				
			}
			return;
		}
		this["txt_name"].onSetFocus = function(){
			this.border = true;
			this.borderColor = 0xDDDDDD;
			r["mcBtnName"]._visible = true;
			
			Key.addListener(this);
			return;
		}
		this["txt_name"].onKillFocus = function(){
			
			this.border = false;
			r["mcBtnName"]._visible = false;
			
			if(!com.dinmax.flash.utilities.movieclip.MovieClipUtils.isMouseOver(r["mcBtnName"])){
							
				this.text = r.theme.getName();
				Key.removeListener(this);
				
			}
			
			return;
		}
					
				
		return;
	}
	
}